package com.school.edupoint.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.school.edupoint.model.Activity;
import com.school.edupoint.model.StudentActivityHistory;
import com.school.edupoint.vo.HomeVO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;

public interface StudentActivityHistoryMapper extends BaseMapper<StudentActivityHistory> {
    void add(Long activityId);

    void updateByASId(String activityId, Integer studentId, StudentActivityHistory history);

    StudentActivityHistory selectIsP(String activityId, Integer studentId);

    HomeVO selectInfo();

    Integer selectTotalPoints();

    Integer selectStatusTwoCount();

    Integer selectStatusTwoPointCount();

    // 已不再使用
    // String selectMaxActivityTitle();
    // String selectMaxActivityImg();

    @Select("SELECT * FROM t_student_activity_history WHERE student_id = #{studentId}")
    List<StudentActivityHistory> selectByStudentIdAndActivityIds(
            @Param("studentId") Integer studentId
    );

    /**
     * 查询参加人数最多的前N个活动
     * @param limit 返回记录数限制
     * @return 包含活动标题和图片的Map列表
     */
    @Select("SELECT a.title, a.poster " +
            "FROM t_student_activity_history sah " +
            "JOIN t_activity a ON sah.activity_id = a.id " +
            "GROUP BY sah.activity_id " +
            "ORDER BY COUNT(sah.student_id) DESC " +
            "LIMIT #{limit}")
    List<Map<String, Object>> selectTopActivities(@Param("limit") int limit);

    /**
     * 查询兑换人数最多的前N个礼物
     * @param limit 返回记录数限制
     * @return 包含礼物标题和图片的Map列表
     */
    @Select("SELECT g.name, g.image_url " +
            "FROM t_student_gift sg " +
            "JOIN t_gift g ON sg.gift_id = g.id " +
            "GROUP BY sg.gift_id " +
            "ORDER BY COUNT(sg.student_id) DESC " +
            "LIMIT #{limit}")
    List<Map<String, Object>> selectTopGifts(@Param("limit") int limit);

    List<Activity> selectPA();

}